﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Interfaces.CommonData;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StockInfoDataLayer;
using StockInfoFacade;
using StockInfoLoader;

namespace TST_ALL
{
    [TestClass]
    public class TST_DB_LAYER
    {
        private readonly string _connString = @"Data Source=bigboy; Integrated Security=SSPI;";
        private readonly string _dbName = @"TestDB";
        

        [TestMethod]
        public void TST_DB_CREATE()
        {
            DBManager mgr = DBManager.CreateInstance(_connString, _dbName);
            mgr.CreateDataBase();
        }

        [TestMethod]
        public void TST_DB_DESTROY()
        {
            DBManager mgr = DBManager.CreateInstance(_connString, _dbName);
            mgr.DropDataBase();
        }

        [TestMethod]
        public void TST_STOCKS_INSERT()
        {
            IndexCompositionLoader ildr = new IndexCompositionLoader();
            List<Stock> lstStocks = ildr.LoadIndexComposition(IndexName.SAndP100);

            DBManager mgr = DBManager.CreateInstance(_connString, _dbName);
            StockTable stbl = new StockTable();

            stbl.PopulateIndexStocks(lstStocks);
        }

        [TestMethod]
        public void TST_ALL_INSERT()
        {
            IndexCompositionLoader ildr = new IndexCompositionLoader();
            List<Stock> lstStocks = ildr.LoadIndexComposition(IndexName.SAndP100);

            DBManager mgr = DBManager.CreateInstance(_connString, _dbName);
            StockTable stbl = new StockTable();

            stbl.PopulateIndexStocks(lstStocks);
        }

        [TestMethod]
        public void TST_INSERT_PRICE()
        {
            DBManager mgr = DBManager.CreateInstance(_connString, _dbName);

            PriceTable pt = new PriceTable();
            List<StockPrice> lstPrices = new List<StockPrice>();
            lstPrices.Add(new StockPrice() {AdjPrice = 0, Date = DateTime.Now, StockId = -1});
            lstPrices.Add(new StockPrice() {AdjPrice = 0, Date = DateTime.Now, StockId = -2 });

            pt.PopulateBulk(lstPrices);
        }

    }
}
